<template>
  <div>
    <el-row :gutter="20" style="margin-top:10px;">
      <el-col :span="8">
        <div class="grid-content bg-purple">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>个人中心</span>
            </div>
            <div style="text-align:center">
              <img id="img" @click="changeDialog=true"  style="cursor: pointer;text-align:center" :src="this.realImg">
            </div>
            <el-divider></el-divider>
            <div class="name-role">
          <span class="sender">Factory-商家角色</span>
            </div>
            <div class="registe-info">
          <span class="registe-info">
            注册时间：2022/5/16 9:40:33
          </span>
            </div>


            <el-divider></el-divider>
            <div class="personal-relation">
              <div class="relation-item">账号:  <div style="float: right; padding-right:20px;">{{user.account}}</div></div>
            </div>
            <div class="personal-relation">
              <div class="relation-item">所属人:  <div style="float: right; padding-right:20px;">{{user.user_name}}</div></div>
            </div>
            <div class="personal-relation">
              <div class="relation-item">联系手机:  <div style="float: right; padding-right:20px;">
                {{user.phone}}</div></div>
            </div>
            <div class="personal-relation">
              <div class="relation-item">联系邮箱:  <div style="float: right; padding-right:20px;">
                {{user.email}}</div></div>
            </div>
          </el-card>
        </div>
      </el-col>
      <el-col :span="16">
        <div class="grid-content bg-purple">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>基本资料</span>
            </div>
            <div>
              <el-form label-width="80px" v-model="dataFrom" size="small" label-position="right">
                <el-form-item label="所属人" prop="nickName">
                  <el-input  auto-complete="off" v-model="user.user_name"></el-input>
                </el-form-item>
                <el-form-item label="联系手机" prop="phone">
                  <el-input auto-complete="off" v-model="user.phone"></el-input>
                </el-form-item>
                <el-form-item label="联系邮箱" prop="homeUrl">
                  <el-input  maxlength="18" v-model="user.email"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button size="mini" type="primary">提交</el-button>
                <el-button size="mini" type="warning" >关闭</el-button>
              </div>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>


    <el-dialog :visible.sync="changeDialog" title="头像修改" width="14%" >
      <div style="border:1px dashed #000;border-radius: 2px ; width: 185px;margin-left: 10px">
        <el-upload
            name="picFile"
            class="avatar-uploader"
            :action="this.action"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "UserInfo",
  data(){
    return{
      action:'',
      user:{},
      imageUrl: '',
      realImg:'',
      changeDialog:false,
    }
  },
  created() {
    this.user=JSON.parse(window.sessionStorage.getItem("user"))
    this.realImg="http://localhost:9001/getImage/"+this.user.user_id+".jpg"
    this.action="http://localhost:9001/up?user_id="+this.user.user_id;
  },
  methods:{

    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      this.changeDialog=false
      this.$message.success("图像修改成功！")
      this.$router.go(0)
    },
    async beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.changeDialog = false
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.changeDialog = false
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    }
  }


}
</script>


<style  scoped>
img{
  width: 200px;
  height: 200px;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.text {
  font-size: 14px;
}
.item {
  margin-bottom: 18px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
.box-card {
  width: 100%;
}

.name-role {
  font-size: 16px;
  padding: 5px;
  text-align:center;
}
.sender{
  text-align:center;
}
.registe-info{
  text-align: center;
  padding-top:10px;
}
.personal-relation {
  font-size: 16px;
  padding: 0px 5px 15px;
  margin-right: 1px;
  width: 100%
}
.relation-item {
  padding: 12px;
}
.dialog-footer{
  padding-top:10px ;
  padding-left: 10%;
}

.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>